package com.hong.spring.profile;

import com.hong.spring.common.config.profile.EnvironmentConfig;
import com.hong.spring.common.config.profile.SystemConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Auther: csh
 * @Date: 2020/7/10 10:43
 * @Description:profile测试
 */
public class ProfileTest {
    public static void main(String[] args) {
//从类路径的xm文件载入上下文定义的信息
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        System.out.println("context 已启动!");
     //   context.getEnvironment().setActiveProfiles("idc");
        //注册主配置类
        context.register(EnvironmentConfig.class);
        context.refresh();
        SystemConfig bean = context.getBean(SystemConfig.class);
        System.out.println(bean.getSystemInfo());
        AnnotationConfigApplicationContext context2 = new AnnotationConfigApplicationContext();
        context2.getEnvironment().setActiveProfiles("dev");
        //注册主配置类
        context2.register(EnvironmentConfig.class);
        context2.refresh();
        SystemConfig bean2 = context2.getBean(SystemConfig.class);
        System.out.println(bean2.getSystemInfo());
    }
}
